

# ==================555555555555555555
def findLengthOfShortestSubarray(arr):
    n = len(arr)
    
    # 最长非递减前缀
    L = 0
    while L < n - 1 and arr[L] <= arr[L + 1]:
        L += 1
    if L == n - 1:
        return 0  
    # 最长非递减后缀
    R = n - 1
    while R > 0 and arr[R - 1] <= arr[R]:
        R -= 1
    # 初始答案：只保留前缀或只保留后缀
    ans = min(n - L - 1, R)
    
    # 双指针：i 为前缀索引，j 为后缀起始索引
    i = 0
    j = R
    while i <= L and j < n:
        if arr[i] <= arr[j]:
            ans = min(ans, j - i - 1)
            i += 1
        else:
            j += 1
    
    return ans

# 测试
if __name__ == "__main__":
    # print(findLengthOfShortestSubarray([1, 2, 3, 10, 4, 2, 3, 5]))  # 输出 3
    # print(findLengthOfShortestSubarray([5, 4, 3, 2, 1]))  # 输出 4
    print(findLengthOfShortestSubarray([1, 2, 3]))  # 输出 0
    # print(findLengthOfShortestSubarray([1]))  # 输出 0